<?php

namespace Es\Struct\Fields;

use Es\Constant\IndexConst;
use Es\Exceptions\CommonExceptions;

/**
 * 索引结构体
 */
class DynamicStruct
{
    
    private $type;
    const TYPE_LIST = [
        IndexConst::DYNAMIC_FALSE  => 1,
        IndexConst::DYNAMIC_TRUE   => 1,
        IndexConst::DYNAMIC_STRICT => 1,
    ];

    /**
     * @throws CommonExceptions
     */
    public function __construct(string $type = IndexConst::DYNAMIC_TRUE){
        $this->type = $type;
        if(!isset(self::TYPE_LIST[$type])){
            throw new CommonExceptions(CommonExceptions::FILEDS_NUM_NOT_FOUNT);
        }
    }   

    public function asArray(): array
    {
        return [
            'dynamic' => $this->type
        ];
    }

}
